/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CaseHistory.java
 *
 * Created on Aug 23, 2011, 8:24:28 AM
 */
package Views;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
import Controllers.AccountDAO;
import Models.Account;
import Controllers.CaseHistoryDAO;
import Models.Cases;
import javax.swing.JOptionPane;

/**
 *
 * @author HUY
 */
public class CaseHistory extends javax.swing.JFrame {

    private DefaultComboBoxModel comModel;
    private DefaultTableModel tblModel;
    private List<Integer> accIDList = new ArrayList<Integer>();
    private int selectedRow; //used select item in  jtable

    /** Creates new form CaseHistory */
    public CaseHistory() {
        initComponents();

        tblModel = new DefaultTableModel();
        tblModel.addColumn("ID");
        tblModel.addColumn("Case Type");
        tblModel.addColumn("Case Time");
        tblModel.addColumn("Reported Time");
        tblModel.addColumn("Approval Date");
        //tblModel.addColumn("Place");
        //tblModel.addColumn("Descriptions");
        tblModel.addColumn("Involvements");
        tblModel.addColumn("Status");
        tblModel.addColumn("Prosecution Desire");
        tblModel.addColumn("Lead OfficerID");
        tblCaseHistory.setModel(tblModel);




        comModel = new DefaultComboBoxModel();
        comLeadOfficerID.setModel(comModel);
        loadDataCombobox();
        //loadDataTable();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblCaseHistory = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        ckProsecution = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtCaseDescriptions = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        comLeadOfficerID = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtCasetype = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCaseInvolvements = new javax.swing.JTextField();
        spnnCaseTime = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        spnnReportTime = new javax.swing.JSpinner();
        spnnApprovalDate = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtCasePlace = new javax.swing.JTextArea();
        combCaseStatus = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        butSearch = new javax.swing.JButton();
        butAddNew = new javax.swing.JButton();
        butEdit = new javax.swing.JButton();
        butShow = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jLabel10.setBackground(new java.awt.Color(204, 204, 255));
        jLabel10.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel10.setText("CASE HISTORY DETAILS MANAGEMENT ");

        tblCaseHistory.setBackground(new java.awt.Color(204, 255, 255));
        tblCaseHistory.setBorder(new javax.swing.border.MatteBorder(null));
        tblCaseHistory.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblCaseHistory.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblCaseHistoryMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblCaseHistory);

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));
        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        ckProsecution.setFont(new java.awt.Font("Tahoma", 0, 13));
        ckProsecution.setText("Prosecuted");
        ckProsecution.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ckProsecutionActionPerformed(evt);
            }
        });

        txtCaseDescriptions.setColumns(20);
        txtCaseDescriptions.setRows(5);
        jScrollPane1.setViewportView(txtCaseDescriptions);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel9.setText("Prosecution Desire:");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel1.setText("Case Type:");

        comLeadOfficerID.setFont(new java.awt.Font("Tahoma", 0, 13));
        comLeadOfficerID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comLeadOfficerID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comLeadOfficerIDActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel5.setText("Case Place:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel11.setText("Serial Number:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel2.setText("Case Time:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel4.setText("Approval Date:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel3.setText("Reported Time:");

        txtCaseInvolvements.setFont(new java.awt.Font("Tahoma", 0, 13));

        spnnCaseTime.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), new java.util.Date(-946742400000L), new java.util.Date(), java.util.Calendar.DAY_OF_YEAR));
        spnnCaseTime.setEditor(new javax.swing.JSpinner.DateEditor(spnnCaseTime, "MM/dd/yyyy hh:mm:ss"));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel7.setText("Case Involvements:");

        spnnReportTime.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), new java.util.Date(-946742400000L), new java.util.Date(), java.util.Calendar.DAY_OF_MONTH));
        spnnReportTime.setEditor(new javax.swing.JSpinner.DateEditor(spnnReportTime, "MM/dd/yyyy hh:mm:ss"));

        spnnApprovalDate.setModel(new javax.swing.SpinnerDateModel());
        spnnApprovalDate.setEditor(new javax.swing.JSpinner.DateEditor(spnnApprovalDate, "MM/dd/yyyy hh:mm:ss"));
        spnnApprovalDate.setEnabled(false);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel8.setText("Case Status:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel6.setText("Case Descriptions:");

        txtCasePlace.setColumns(20);
        txtCasePlace.setRows(5);
        jScrollPane3.setViewportView(txtCasePlace);

        combCaseStatus.setFont(new java.awt.Font("Tahoma", 0, 13));
        combCaseStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(174, 174, 174)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(spnnReportTime, javax.swing.GroupLayout.PREFERRED_SIZE, 149, Short.MAX_VALUE)
                        .addComponent(spnnCaseTime, javax.swing.GroupLayout.PREFERRED_SIZE, 149, Short.MAX_VALUE)
                        .addComponent(txtCasetype, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                                .addGap(39, 39, 39)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(combCaseStatus, 0, 145, Short.MAX_VALUE)
                            .addComponent(txtCaseInvolvements, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                .addGap(5, 5, 5)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ckProsecution, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(43, 43, 43)
                        .addComponent(comLeadOfficerID, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                                    .addGap(18, 18, 18)))
                            .addGap(33, 33, 33)
                            .addComponent(spnnApprovalDate, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                            .addGap(197, 197, 197))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                            .addGap(172, 172, 172))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                            .addGap(196, 196, 196)))
                    .addGap(317, 317, 317)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(txtCasetype))
                    .addComponent(txtCaseInvolvements))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(combCaseStatus)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(spnnCaseTime)
                        .addGap(10, 10, 10)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(spnnReportTime)
                        .addGap(65, 65, 65)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                        .addGap(79, 79, 79))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(ckProsecution, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(61, 61, 61)))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(comLeadOfficerID))
                        .addGap(65, 65, 65)))
                .addGap(31, 31, 31))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(159, 159, 159))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(42, 42, 42)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(22, 22, 22)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                            .addGap(22, 22, 22)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(4, 4, 4)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(spnnApprovalDate))
                            .addGap(21, 21, 21)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)))
                    .addGap(162, 162, 162)))
        );

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));
        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        butSearch.setFont(new java.awt.Font("Tahoma", 0, 14));
        butSearch.setText("Search");
        butSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butSearchActionPerformed(evt);
            }
        });

        butAddNew.setText("Add New");
        butAddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butAddNewActionPerformed(evt);
            }
        });

        butEdit.setText("Edit");
        butEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butEditActionPerformed(evt);
            }
        });

        butShow.setFont(new java.awt.Font("Tahoma", 0, 13));
        butShow.setText("Show All");
        butShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butShowActionPerformed(evt);
            }
        });

        jButton1.setText("Save");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                    .addComponent(butSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                    .addComponent(butShow, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addGap(12, 12, 12)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(butEdit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                        .addComponent(butAddNew, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                    .addContainerGap()))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(97, 97, 97)
                .addComponent(butSearch)
                .addGap(27, 27, 27)
                .addComponent(jButton1)
                .addGap(27, 27, 27)
                .addComponent(butShow)
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(butAddNew)
                    .addGap(18, 18, 18)
                    .addComponent(butEdit)
                    .addContainerGap(206, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addComponent(jLabel10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(62, 62, 62)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                .addGap(62, 62, 62))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, 0, 287, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                .addGap(52, 52, 52))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void butShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butShowActionPerformed
// TODO add your handling code here:
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
    String strCaseTime = formatter.format(spnnCaseTime.getValue());
    String strReportTime = formatter.format(spnnReportTime.getValue());
    String strApprovalDate = formatter.format(spnnApprovalDate.getValue());
    List<Cases> lisCase = CaseHistoryDAO.loadAllCase();
    while (tblModel.getRowCount() > 0) {
        tblModel.removeRow(0);
    }
    for (Cases cases : lisCase) {
        tblModel.addRow(new String[]{cases.getCaseID() + "", cases.getCaseType(), strCaseTime, strReportTime, strApprovalDate,
                    cases.getCaseInvolvements(), cases.getCaseStatus() + "", cases.isProsecutionDesire() ? "Prosecuted" : "Unprosecuted", cases.getLeadOfficerID() + ""});
    }
}//GEN-LAST:event_butShowActionPerformed

private void butEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butEditActionPerformed
    // TODO add your handling code here:
    //JOptionPane.showInputDialog();
}//GEN-LAST:event_butEditActionPerformed

private void butAddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butAddNewActionPerformed
// TODO add your handling code here:
    SimpleDateFormat formatter = new SimpleDateFormat("DD/mm/yyyy");
    //||  ||  || 
    if (txtCasetype.getText().trim().length() == 0) {
        JOptionPane.showConfirmDialog(this, "You must Enter Case Type");
    } else if (txtCasePlace.getText().trim().length() == 0) {
        JOptionPane.showConfirmDialog(this, "You must Enter Case Place");
    } else if (txtCaseInvolvements.getText().trim().length() == 0) {
        JOptionPane.showConfirmDialog(this, "You must Enter Case Involvements");
    } else if (txtCaseDescriptions.getText().trim().length() == 0) {
        JOptionPane.showConfirmDialog(this, "You must Enter Case Descriptions");
    } else {
        Cases cases = new Cases();
        //set enable or disable Prosecution Desire
        cases.setProsecutionDesire(ckProsecution.isSelected());
        cases.setCaseType(txtCasetype.getText());
        //set time 
        String strCaseTime = formatter.format(spnnCaseTime.getValue());
        try {
            cases.setCaseTime(formatter.parse(strCaseTime));
        } catch (ParseException ex) {
            Logger.getLogger(CaseHistory.class.getName()).log(Level.SEVERE, null, ex);
        }
        String strReportTime = formatter.format(spnnReportTime.getValue());
        try {
            cases.setReportedTime(formatter.parse(strReportTime));
        } catch (ParseException ex) {
            Logger.getLogger(CaseHistory.class.getName()).log(Level.SEVERE, null, ex);
        }
        String strApprovalDate = formatter.format(spnnApprovalDate.getValue());
        try {
            cases.setApprovalDate(formatter.parse(strApprovalDate));
        } catch (ParseException ex) {
            Logger.getLogger(CaseHistory.class.getName()).log(Level.SEVERE, null, ex);
        }
        //set case place
        cases.setCasePlace(txtCasePlace.getText());
        //set case Descriptions
        cases.setCaseDescriptions(txtCaseDescriptions.getText());
        cases.setCaseInvolvements(txtCaseInvolvements.getText());
        cases.setCaseStatus(Integer.parseInt(combCaseStatus.getSelectedItem().toString()));
        //set case
        cases.setLeadOfficerID(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()));
        //System.out.println(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()) + 1);

        if (CaseHistoryDAO.addNewCases(cases)) {
            JOptionPane.showConfirmDialog(this, "Add New successful");
        } else {
            JOptionPane.showConfirmDialog(this, "Add New Not successful");
        }
        //set case
        cases.setLeadOfficerID(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()));
        //System.out.println(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()) + 1);

        if (CaseHistoryDAO.addNewCases(cases)) {
            JOptionPane.showConfirmDialog(this, "Add New successful");
        } else {
            JOptionPane.showConfirmDialog(this, "Add New Not successful");
        }
        //set case
        cases.setLeadOfficerID(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()));
        //System.out.println(Integer.parseInt(comLeadOfficerID.getSelectedItem().toString()) + 1);

        if (CaseHistoryDAO.addNewCases(cases)) {
            JOptionPane.showConfirmDialog(this, "Add New successful");
        } else {
            JOptionPane.showConfirmDialog(this, "Add New Not successful");
        }

    }





}//GEN-LAST:event_butAddNewActionPerformed

private void butSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSearchActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_butSearchActionPerformed

private void comLeadOfficerIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comLeadOfficerIDActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_comLeadOfficerIDActionPerformed

private void ckProsecutionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ckProsecutionActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ckProsecutionActionPerformed

private void tblCaseHistoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblCaseHistoryMouseClicked
// TODO add your handling code here:
    selectedRow = tblCaseHistory.getSelectedRow();
    String nameValue = (String) tblCaseHistory.getValueAt(selectedRow, 1);
    String addrValue = (String) tblCaseHistory.getValueAt(selectedRow, 1);
    txtCasetype.setText(nameValue);
    
   // txtCasePlace.setText(addrValue);
    
    //CaseHistoryViewDetail show = new CaseHistoryViewDetail();
    
}//GEN-LAST:event_tblCaseHistoryMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CaseHistory().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butAddNew;
    private javax.swing.JButton butEdit;
    private javax.swing.JButton butSearch;
    private javax.swing.JButton butShow;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JCheckBox ckProsecution;
    private javax.swing.JComboBox comLeadOfficerID;
    private javax.swing.JComboBox combCaseStatus;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSpinner spnnApprovalDate;
    private javax.swing.JSpinner spnnCaseTime;
    private javax.swing.JSpinner spnnReportTime;
    private javax.swing.JTable tblCaseHistory;
    private javax.swing.JTextArea txtCaseDescriptions;
    private javax.swing.JTextField txtCaseInvolvements;
    private javax.swing.JTextArea txtCasePlace;
    private javax.swing.JTextField txtCasetype;
    // End of variables declaration//GEN-END:variables

    private void loadDataCombobox() {
        AccountDAO accDAO = new AccountDAO();
        ArrayList<Account> listAcc = accDAO.loadALL();
        comLeadOfficerID.removeAllItems();
        for (Account accounts : listAcc) {
            //comModel.addElement(accounts.getAccSerialNo());
            accIDList.add(accounts.getID());
            comLeadOfficerID.addItem(accounts.getID());
        }
    }

    private void loadDataTable() {
        CaseHistoryDAO caseDAO = new CaseHistoryDAO();
        List<Cases> lisCase = caseDAO.loadAllCase();
        while (tblModel.getRowCount() > 0) {
            tblModel.removeRow(0);
        }
        for (Cases cases : lisCase) {
            tblModel.addRow(new String[]{cases.getCaseID() + "", cases.getCaseType(), cases.getCaseTime().toString(), cases.getReportedTime().toString(), cases.getApprovalDate().toString(),
                        cases.getCasePlace(), cases.getCaseDescriptions(), cases.getCaseInvolvements(), cases.getCaseStatus() + "", cases.isProsecutionDesire() ? "Prosecuted" : "Unprosecuted", cases.getLeadOfficerID() + ""});
        }

    }
}